package com.itheima.service.impl;

import com.itheima.dao.UserDao;
import com.itheima.service.UserService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

// @Service("userService")
// @Order(3)
//默认的是初始化就加载,如果用Lazy 就可以延迟加载
// @Lazy
// @DependsOn("userService2")
public class UserServiceImpl implements UserService, InitializingBean {

    //按照类型装配,如果通类型,就按照@Primary修饰的自动装配

    @Autowired
    private UserDao userDao;
    //
    // @Resource(name = "bookDao")
    // // @Inject
    // // @Named
    // private BookDao bookDao;

    public void save() {
        System.out.println("user service running...");
        System.out.println("------------");
        userDao.save();
        System.out.println("------------");
        // bookDao.save();
    }

    @PostConstruct
    public void init() {
        System.out.println("user servier init...");
    }

    @PreDestroy
    public void destroy() {
        System.out.println("user servier destroy...");
    }

    //创建后处理
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("UserServiceImpl 创建完成");
    }
}
